/**
 * For employees only. Shows the names of all projects stored in the database.
 * All projects will link to displayOneProject(). displayCommentIcon() will
 * display an icon if the employee has made a comment in the spesific project.
 * If "pw" is set, the employee will see whether he has viewed a certain project
 */
function displayAllProjects() {    
    $.ajax ({
        url : 'higface/library/getAllProjects.php',
        type : 'POST',
        success : function (tmp) {
            data = eval ('('+tmp+')');
            if(data.error){
                alert(data.error);
                return;
            }  
            
            /* In every project, create list- and hyperlinkelements and link
             * to displayOneProject. */
            var proList = document.getElementById('projectListen'); //get the projectlist
            var header = document.createElement('h1');          //creates a header tag
            header.innerHTML = "Alle prosjektforslag:";         //display header text
            proList.appendChild(header);                    // add header to projectlist
            
            for(project in data) {                   // loops trough all projects
                
                var list = document.createElement('li');    // creates a list tag for all projects
                list.value = data[project][0];         // add project id to list value
                list.setAttribute('class', 'studentlist');  // add class to list
                var link = document.createElement('a'); // creates a link to list tag with onclick event to display one project
                 
                link.innerHTML = '<a href="javascript: ;" onclick="displayOneProject\
                    ('+data[project][0]+');" >'+ data[project][2] + // display the project name insde link tag
                '<b id="commentIco'+data[project][0]+'"></b></a>';//The tag to know where
                                                              //to place the comment icon.
                /* In the projects the employee has seen, set the list's
                 * background-color to be gray. */
                if(data[project]['viewed'] == 1) {
                    list.style.backgroundColor="#f0f0f0"; //Gray to indicate it is viewed
                }
                list.appendChild(link);         // Connect hyperlink to list.
                proList.appendChild(list);      // Append list to projectList 
                /* 
                 * Checks if employee has made a comment to the project, and display
                 * an icon if the comment has taken place: 
                 */
                if (data[project]['comment'] !=  "" && data[project]['comment'] != null) {
                    document.getElementById('commentIco'+data[project][0]).
                    innerHTML = ('<img id="CommentIco" src="LnF/chat.ico" />');
                }     
            } // end for
        } // end success
    }); // end $.ajax
} // end function

    
/**
 * Set that the project is viewed.
 */
function projectViewed(projectId) { 
    $.ajax({
        url: 'higface/employee/library/setProjectViewed.php',
        type: 'POST',
        data: {
            'pid' : projectId 
        },
        success: function(tmp){
        }
    });
}